#include <mysql/mysql.h>
#include <string>
#include <ctime>
using namespace std;

class Connection
{
public:
    Connection();
    ~Connection();
    bool connect(string ip,
                 unsigned short port,
                 string user,
                 string password,
                 string dbname);
    bool update(string sql);
    MYSQL_RES *query(string sql);
    void refreshAliveTime() { _alivetime = clock(); }
    clock_t getAliveTime() const { return clock() - _alivetime; }

private:
    MYSQL *_conn; // 与MySQL的一条连接
    clock_t _alivetime; // 连接的建立时间
};